<?php session_start();

$u=$_GET["u"];
$c=$_GET["c"];

$username = "root";
$pass = "";
$con = mysql_connect("localhost",$username,$pass);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


@mysql_select_db("progin_171_13509008", $con);

$query = "select status from like_content where user_name ='".$u."' and id_content =".$c;
$result = mysql_query($query);


$insquery = "";
$case = 0;

if($_SESSION['session'] == false)
{
    if (mysql_num_rows($result) == 0) { //user belum pernah memasukkan data
        $insquery = "insert into like_content (user_name,id_content,status) VALUES ('".$u."',".$c.",1)";
        $case = 0;
    } else {
        $row = mysql_fetch_array($result);
        $status = $row[0];
        if($status == 1 ) {$insquery="update like_content set status = 0 where user_name='".$u."' and id_content=".$c." "; $case = 1;}
        else{$insquery="update like_content set status = 1 where user_name='".$u."' and id_content=".$c." "; $case = 2;}
    }
    mysql_query($insquery);
}

echo $case;
mysql_close();
?>
